﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class AddSlideShow : System.Web.UI.UserControl
    {
        public string filePathSlide;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_Slide", "Slide_ID"));
                if (txtLink.Text != "")
                {
                        if (fulImageSlide.HasFile)
                        {
                            if (LIB.Validate.CheckFileType(fulImageSlide.FileName))
                            {
                                
                                    int idnextslideshow = nextid + 1;
                                    string linkimage = fulImageSlide.FileName;
                                    LIB.Validate saveimage = new LIB.Validate();
                                    saveimage.ThayDoiKichThuocAnh(Server.MapPath("/Resources/Images/Images-Slide/"), linkimage, 940, fulImageSlide.PostedFile.InputStream);
                                    filePathSlide = "/Resources/Images/Images-Slide/" + fulImageSlide.FileName;
                                    string value = "" + idnextslideshow + ",N'" + txtName.Text +"',N'"+txtTitle.Text+"',N'"+txtPlace.Text+"','"+ filePathSlide + "',N'"+txtAlt.Text+"','" + txtLink.Text + "',N'"+txtSize.Text+"','" + DateTime.Now.ToString() + "'";
                                    List<string> values = new List<string>();
                                    values.Add(value);
                                    DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Slide", "insertonerow", values, false);
                                    Response.Redirect("/Admin/Index.aspx?panel=5&sub=0");                               
                              
                            }
                            else
                            {
                                Response.Write("<script>alert('Chỉ có thể upload file(.jpg,.png,.jpeg)')</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert('Bạn vui lòng upload ảnh SlideShow...')</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('Vui lòng nhập tên tiêu đề slideshow...')</script>");
                    }
            }       
        }
    }